# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=libgda
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.9
pkgrel=3
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="Data abstraction library based on GLib (mingw-w64)"
license=("LGPL 2")
url="https://www.gnome-db.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview3"
         "${MINGW_PACKAGE_PREFIX}-goocanvas"
         "${MINGW_PACKAGE_PREFIX}-iso-codes"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt"
         "${MINGW_PACKAGE_PREFIX}-glade")
makedepends=("${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-iso-codes"
             #"${MINGW_PACKAGE_PREFIX}-db"
             "${MINGW_PACKAGE_PREFIX}-firebird2"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-openldap"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "flex"
             "gettext"
             "gnome-doc-utils"
             "gtk-doc"
             "libintl"
             "patch")
options=('strip' '!debug' 'staticlibs')
source=(https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-${pkgver}.tar.xz
        001-lemon.patch
        002-mysql-m4.patch
        003-give-cc-to-gir-scanner.all.patch
        004-add-missing-symbols.patch
        005-hack-convert-path-back-to-unix.patch
        006-Use-goocanvas-3.0.patch
        007-Use-single-header-with-GtkSource.patch
        008-lemon-fix-segfault.patch)
sha256sums=('59caed8ca72b1ac6437c9844f0677f8a296d52cfd1c0049116026abfb1d87d9b'
            'e61c10e41ea2b343c6a50d0cbf1f2912b9d9273882249a998f60cda2f4a94d4c'
            '5a9959715e63a82e5bf62bb3e6ffbe4d4b587094d13b671e2a676720c765e048'
            'a0a2e3ca548feedc6502f29ff0ef5f047bf2a7dabd7722011147872a5aea733b'
            '852956cb1f2cd77174b53ab56f509f4766442277d236b0e0eed5650f288d9c89'
            '88718da49d5c9671f4b7c7ac4a859762012c723928f3ad7c7000bad776200596'
            '81ab26fd12f7174e880815f6aa624c24821b1f9c7f386ae566293df7f041b25b'
            '104594a6034b041d87c1129b0b5544c8899393d66a6a0fb7a8b55f7fcb77e560'
            '677ac2d5b6936e8eaf676c0a79027065c6f41d8f46d385c56ad5b716a1367034')

prepare() {
  cd ${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/001-lemon.patch
  patch -p1 -i ${srcdir}/002-mysql-m4.patch
  patch -p1 -i ${srcdir}/003-give-cc-to-gir-scanner.all.patch
  patch -p1 -i ${srcdir}/004-add-missing-symbols.patch
  patch -p1 -i ${srcdir}/005-hack-convert-path-back-to-unix.patch

  # https://github.com/archlinux/svntogit-community/tree/packages/libgda/trunk
  patch -p1 -i ${srcdir}/006-Use-goocanvas-3.0.patch
  patch -p1 -i ${srcdir}/007-Use-single-header-with-GtkSource.patch

  # https://gitlab.gnome.org/GNOME/libgda/-/merge_requests/176
  patch -p1 -i ${srcdir}/008-lemon-fix-segfault.patch

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  # --with-java=no as CI has Java preinstlled

  CFLAGS+=" -Wno-deprecated-declarations" \
  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-gda-gi \
    --enable-introspection \
    --enable-gtk-doc-html=no \
    --without-help \
    --enable-system-mdbtools=no \
    --enable-gi-system-install=no \
    --with-ldap=${MINGW_PREFIX} \
    --with-mysql=${MINGW_PREFIX} \
    --with-mysql-libdir-name=lib \
    --with-postgres=${MINGW_PREFIX} \
    --with-firebird=${MINGW_PREFIX} \
    --with-bdb=${MINGW_PREFIX} \
    --with-java=no

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
